<?php
/**
 * Created by PhpStorm.
 * User: helloxingtongshi
 * Date: 2016-05-20
 * Time: 15:54
 */
if(isset($_POST["addmaterial"])||isset($_POST["updatematerial"])){
    //接收数据
    $material = array(
        'materialId' => empty($_POST['materialId']) ? 0 : $_POST['materialId'],
        'materialname' => @$_POST['materialname'],
        'price' => @$_POST['price'],
        'num' => @$_POST['num'],
        'entertime' => @$_POST['entertime'],
        'entername' => @$_POST['entername'],
        'suppliername' => @$_POST['suppliername'],
        'supplierphone' => @$_POST['supplierphone'],
        'bankname' => @$_POST['bankname'],
        'bankid' => @$_POST['bankid'],
        'sum' => @$_POST['sum'],
    );
}
/*if(!isset($_POST["addmaterial"])&&!isset($_POST["updatematerial"])&&isset($_POST["num"])&&isset($_POST["price"])){
    //接收选择商品名称后的数据
    $addmaterials = array(
        'materialId' => empty($_POST['materialId']) ? 0 : $_POST['materialId'],
        'materialname' => $_POST['materialname'],
        'price' => $_POST['price'],
        'num' => $_POST['num'],
        'entertime' => $_POST['entertime'],
        'entername' => $_POST['entername'],
        'suppliername' => $_POST['suppliername'],
        'supplierphone' => $_POST['supplierphone'],
        'bankname' => $_POST['bankname'],
        'bankid' => $_POST['bankid'],
        'sum' => $_POST['sum'],
    );
}*/
require 'sql.php';//使用require语句包含并执行sql.php
//  $material1=$_GET["material"];
//  echo $material1;
// exit;

//添加
if(isset($_POST["addmaterial"])) {
    $Msql = "insert into material (entertime,entername,price,num,suppliername,supplierphone,materialname,bankname,bankid,sum) values('{$material['entertime']}','{$material['entername']}','{$material['price']}','{$material['num']}','{$material['suppliername']}','{$material['supplierphone']}','{$material['materialname']}','{$material['bankname']}','{$material['bankid']}','{$material['sum']}')";
    $Mresult = mysql_query($Msql);
    if ($Mresult > 0) {
        echo "添加成功";
    } else {
        echo "添加失败";
    }
}
//删除
if(isset($_POST["delmaterial"])){
    $id = $_POST['materialId'];
    $del="delete from material where materialId=$id";
    $resultd= mysql_query($del);
    if($resultd != 0){
        echo  "删除成功";
    }else{
        echo  "删除失败";
    }
}
//修改
if(isset($_POST["updatematerial"])){
    $id = $_POST['materialId'];
    $update="update material set  entertime='{$material['entertime']}',entername='{$material['entername']}',price='{$material['price']}',num='{$material['num']}',suppliername='{$material['suppliername']}',supplierphone='{$material['supplierphone']}',materialname='{$material['materialname']}',bankname='{$material['bankname']}',bankid='{$material['bankid']}'  where materialId=$id";
    $resultu= mysql_query($update);
    if($resultu != 0){
        echo  "更新成功";
    }else{
        echo  "更新失败".mysql_error();
    }
}
$add="select materialname,price,num,entertime,entername,suppliername,supplierphone,materialId,bankname,bankid,sum from material";//查询遍历
$aresult= mysql_query($add);
while($row=mysql_fetch_row($aresult)){
    $materiall[]=$row;
}
?>